package com.hzyl.famousreader.router.interceptor;

import android.content.Context;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPUtils;
import com.hzyl.famousreader.Constant;
import com.hzyl.famousreader.router.Router;

/**
 * 登陆拦截器
 */
@Interceptor(priority = 1, name = "登陆用拦截器")
public class LoginInterceptor implements IInterceptor {

  @Override
  public void process(Postcard postcard, InterceptorCallback callback) {
    if (postcard.getExtra() == Router.EXTRA_LOGIN_NEED) {
      boolean isLogin = SPUtils.getInstance().getBoolean(Constant.SP_IS_LOGIN, false);
      if (isLogin) {
        callback.onContinue(postcard);
      }
      ARouter.getInstance().build(Router.ACTIVITY_LOGIN).navigation();
    } else {
      callback.onContinue(postcard);
    }
  }

  @Override
  public void init(Context context) {
  }
}
